package net.dopan.pigframe.oss.storagecloud;

import net.dopan.pigframe.core.utils.SpringContextUtils;
import net.dopan.pigframe.core.utils.SysConfigConstant;
import net.dopan.pigframe.oss.service.OSSConfigService;
import net.dopan.pigframe.oss.utils.ConfigConstant;

/**
 * @Package: net.dopan.pigframe.oss.storagecloud
 * @Title: OSSFactory
 * @Description: 文件上传Factory
 * @author: 刘宽
 * @date: 2018/8/8 15:34
 */
public final class OSSFactory {
    private static OSSConfigService ossConfigService;

    static {
        OSSFactory.ossConfigService = SpringContextUtils.getBean("ossConfigService");
    }

    public static AbstractCloudStorageService build(){
        //获取云存储配置信息
        CloudStorageConfig config = ossConfigService.getConfigObject(SysConfigConstant.CLOUD_STORAGE_CONFIG_KEY, CloudStorageConfig.class);

        if(config.getType() == ConfigConstant.CloudService.FASTDFS.getValue()){
            return new FastDFSStorageService(config);
        }else if(config.getType() == ConfigConstant.CloudService.QINIU.getValue()){
            return new QiniuCloudStorageService(config);
        }else if(config.getType() == ConfigConstant.CloudService.ALIYUN.getValue()){
            return new AliyunCloudStorageService(config);
        }else if(config.getType() == ConfigConstant.CloudService.QCLOUD.getValue()){
            return new QcloudCloudStorageService(config);
        }
        return null;
    }

}
